package cn.tedu.dimanage.apply.webapi.controller;

import cn.tedu.dimanage.apply.service.IApplyService;
import cn.tedu.dimanage.common.web.JsonResult;
import cn.tedu.dimanage.pojo.dto.ApplyAddNewDTO;
import cn.tedu.dimanage.pojo.dto.ApplyCheckDTO;
import cn.tedu.dimanage.pojo.dto.ApplyUpdateDTO;
import cn.tedu.dimanage.pojo.vo.ApplyDetailsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Classname: ApplyController
 * @Author: bromide
 * @CreateTime: 2022/6/21--下午11:05
 * @Version: V1.0
 * @Description:
 */
@RestController
@RequestMapping(value = "/apply" , produces = "application/json;charset=utf-8")
public class ApplyController {
    @Autowired
    IApplyService applyService;

    @PostMapping("/add-new")
    public JsonResult<Void> addApply(ApplyAddNewDTO applyAddNewDTO){
        applyService.addApply(applyAddNewDTO);
        return JsonResult.ok();
    }

    @GetMapping("/selectList")
    public JsonResult<List<ApplyDetailsVO>> selectApplyList (String keyword){
        List<ApplyDetailsVO> list = applyService.selectApplyList(keyword);
        return JsonResult.ok(list);
    }

    @GetMapping("/selectListByUserId")
    public JsonResult<List<ApplyDetailsVO>> selectApplyListByUserId (Long userId){
        List<ApplyDetailsVO> list = applyService.selectApplyListByUserId(userId);
        return JsonResult.ok(list);
    }

    @GetMapping("/selectOut")
    public JsonResult<List<ApplyDetailsVO>> selectApplyOut(String keyword){
        List<ApplyDetailsVO> applyDetailsVOS = applyService.selectApplyOut(keyword);
        return JsonResult.ok(applyDetailsVOS);
    }

    @PostMapping("/update-admin")
    public JsonResult<Void> updateApplyByAdmin(ApplyCheckDTO applyCheckDTO){
        applyService.updateApplyByAdmin(applyCheckDTO);
        return JsonResult.ok();
    }

    @PostMapping("/update-user")
    public JsonResult<Void> updateApplyByUser(ApplyUpdateDTO applyUpdateDTO){
        applyService.updateApplyByUser(applyUpdateDTO);
        return JsonResult.ok();
    }

    @GetMapping("/deleteById")
    public JsonResult<Void> deleteApplyById(Long id){
        applyService.deleteApplyById(id);
        return JsonResult.ok();
    }

}
